<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="net.sf.json.JSONObject,weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%
	BaseBean bb= new BaseBean();
	RecordSet rs = new RecordSet();
	RecordSet rs_mx = new RecordSet();
	RecordSet rs_x = new RecordSet();
	Map<String, String> dataMap = new HashMap<String, String>();
	bb.writeLog("====getPro_BB====");
	String productMM = request.getParameter("productMM");
	productMM = getproductMM(productMM);
	bb.writeLog("productMM-=="+productMM);
	String qzd = productMM.substring(0,8);
	String bbh = productMM.substring(8,10);
	String flag = "0";
	String message = "";
	String lsh = "";
	String bm = "";
	String bbh_16 = "";
	String sql = "select 1 from uf_minorbbh where qzd ='"+qzd+"'";
	bb.writeLog("sql==="+sql);
	rs.execute(sql);
	boolean ishave = false;
	if(rs.next()){
		ishave =true;
	}
	if(ishave){
		//之前存在流水	
		String sql_max = "select max(bbh) as bbh from uf_minorbbh where qzd ='"+qzd+"'";
		rs.execute(sql_max);
		String bbh_old="";
		if(rs.next()){
			bbh_old = Util.null2String(rs.getString("bbh"));
		}
		bb.writeLog("bbh_old==="+bbh_old);
		if(Integer.parseInt(bbh_old)==99){
			flag = "1";
			message = "Error!";
		}else{
			bbh = String.valueOf(Integer.parseInt(bbh_old)+1);
			bbh_16 = Integer.toHexString(Integer.parseInt(bbh));
			if(bbh_16.length()==1){
				bbh_16="0"+bbh_16;
			}
		}
		bm = qzd+bbh_16;
		message = "SUCCESS";
		flag = "0";
		bb.writeLog("bbh=="+bbh);
		bb.writeLog("bbh_16=="+bbh_16);
	}else{
		bm = qzd+"01";
		bbh = "1";
		message = "SUCCESS!";
		flag = "0";
	}
	
	
	dataMap.put("qzd",qzd);
	dataMap.put("bm",bm);
	dataMap.put("bbh",bbh);
	dataMap.put("lsh",lsh);
	dataMap.put("message",message);
	dataMap.put("flag",flag);
	JSONObject json = JSONObject.fromObject(dataMap);
	out.print(json.toString());
%>
<%! 
public String getproductMM(String str){
	String ret = "";
	RecordSet rs = new RecordSet();
	String sql = "select wlh from uf_mcr where id='"+str+"'";
	rs.execute(sql);
	if(rs.next()){
		ret = Util.null2String(rs.getString("wlh"));
	}
	return ret;
}
%>

	